home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 March: Reference Library / Dev.CD Mar 96 RL / Dev.CD Mar 96 RL.toast / Technical Documentation / develop / develop Issue 25 / develop Issue 25 code / QD3D to QTVR / ArticleCode / Source / FramesPanorama.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-21  |  3.0 KB  |  138 lines  |  [TEXT/MPCC]

  1. #include "QD3DtoQTVR.h"
  2. #include "extern.h"
  3. #include "camera.h"
  4. #include "draw.h"
  5. #include "Panorama.h"
  6. #include "file.h"
  7. #include "AEVT.h"
  8. #include "MyMovies.h"
  9. #include "document.h"
  10.  
  11. #define factor 32.0
  12.                 
  13. void MyConvert3DMFToPano(FSSpec *myFSS)
  14. {
  15.     DocumentPtr    theDocument;
  16.     
  17.     // Create the document record and make the view and camera
  18.     theDocument = MyNewDocument();
  19.     if (!theDocument)
  20.         return;
  21.     
  22.     // Read the model and add it to the document record's group
  23.     if(MyOpenFile(myFSS, theDocument)) {
  24.         MyCloseDocument(theDocument);
  25.         return;
  26.     }
  27.  
  28.     // Set up the initial camera position for object rendering
  29.     MyInitPanoCamera(theDocument);
  30.  
  31.     // Draw to the screen
  32.     MyDrawOffScreen(theDocument);
  33.     MyDrawOnScreen(theDocument);    
  34.  
  35.     // Assign the Codec type
  36.     theDocument->theCodecType = kMyCodec;
  37.  
  38.     // generate the pano frames
  39.     MyGeneratePanoFrames(theDocument);
  40.  
  41.     // Clean up
  42.     MyCloseDocument(theDocument);
  43. }
  44.  
  45. void MyGeneratePanoFrames(DocumentPtr theDocument)
  46. {
  47.     PicHandle            thePict;
  48.     float                zAngle;
  49.     long                counter = 0;
  50.     Str255                fName;
  51.     GWorldPtr            gw;
  52.     GDHandle            gd;
  53.     FSSpec                outSpec;
  54.     
  55.     GetGWorld(&gw, &gd);
  56.     SetGWorld(theDocument->theWindow,nil);
  57.     
  58.     outSpec = theDocument->theFileSpec;
  59.     
  60.     for(zAngle = 360;zAngle >0; zAngle -= 30) {
  61.         short    i;
  62.         
  63.         if (Button())
  64.             break;
  65.         
  66.         // Rotate camera for next shot
  67.         MyRotateCameraY(theDocument, -30.0*kQ3Pi/180.0);
  68.         
  69.         // Render image
  70.         SetGWorld(theDocument->theWindow,nil);
  71.         MyDrawOffScreen(theDocument);
  72.         MyDrawOnScreen(theDocument);
  73.     
  74.         // Get image and copy it to destination.
  75.         SetGWorld(theDocument->drawContextOffscreen,nil);
  76.         thePict = OpenPicture(&theDocument->drawContextOffscreen->portRect);
  77.         LockPixels(theDocument->drawContextOffscreen->portPixMap);
  78.         CopyBits((BitMap*)&theDocument->drawContextOffscreen->portPixMap,
  79.                             (BitMap*)&theDocument->drawContextOffscreen->portPixMap,
  80.                             &theDocument->drawContextOffscreen->portRect,
  81.                             &theDocument->drawContextOffscreen->portRect,
  82.                             srcCopy,NULL);
  83.         UnlockPixels(theDocument->drawContextOffscreen->portPixMap);
  84.         ClosePicture();
  85.         
  86.         // Create file name for next image.
  87.         counter++;
  88.         NumToString(counter,fName);
  89.         if (counter >= 10)
  90.             for(i = 0; i <= fName[0]; i++)
  91.                 outSpec.name[i] = fName[i];
  92.         else {
  93.             outSpec.name[0] = '\2';
  94.             outSpec.name[1] = '0';
  95.             outSpec.name[2] = fName[1];
  96.         }
  97.         
  98.         // Save new image to file.    
  99.         MySavePICT(thePict,&outSpec);
  100.         KillPicture(thePict);
  101.     }
  102.  
  103.     // Clean up.
  104.     SetGWorld(theDocument->theWindow,nil);
  105.     MyDrawOffScreen(theDocument);
  106.     MyDrawOnScreen(theDocument);
  107.     SetGWorld(gw,gd);
  108. }
  109.  
  110.  
  111. OSErr    MySavePICT(PicHandle    picture,FSSpec    *theSpec) 
  112. {
  113.     long    bytes;
  114.     OSErr    err;
  115.     short    fRefNum;
  116.     
  117.     FSpDelete (theSpec);
  118.     err = FSpCreate (theSpec, '3DVR', 'PICT', smCurrentScript);
  119.     if(err)
  120.         return err;
  121.     
  122.     err = FSpOpenDF (theSpec, fsRdWrPerm, &fRefNum);
  123.     if(err)
  124.         return err;
  125.     
  126.     bytes = 512;
  127.     FSWrite(fRefNum,&bytes,(Ptr)NULL);
  128.     HLock((Handle)picture);
  129.     bytes = GetHandleSize((Handle)picture);
  130.     FSWrite(fRefNum,&bytes,(Ptr)(*picture));
  131.     HUnlock((Handle)picture);
  132.     FSClose(fRefNum);
  133.     FlushVol(theSpec->name,theSpec->vRefNum);
  134.     
  135.     return err;
  136. }
  137.  
  138.